FROM golang:1.14 as builder

ENV GO111MODULE=on \
    GOPROXY=https://goproxy.cn,direct
WORKDIR /go/src/
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build  -o /app .


FROM alpine:3.14

ENV	SERVICE_USER=myuser \
	SERVICE_UID=10001 \
	SERVICE_GROUP=mygroup \
	SERVICE_GID=10001
RUN	addgroup -g ${SERVICE_GID} ${SERVICE_GROUP} && \
	adduser -g "${SERVICE_NAME} user" -D -H -G ${SERVICE_GROUP} -s /sbin/nologin -u ${SERVICE_UID} ${SERVICE_USER}
WORKDIR /
COPY --from=builder /app /app
RUN chmod +x /app && \
    chown -R ${SERVICE_USER}:${SERVICE_GROUP} /app
USER ${SERVICE_USER}
EXPOSE 8002
CMD ["/app"]